<html>
<head><meta charset="utf-8"><title>Stack alignment in leaf function · t-compiler/wg-llvm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/index.html">t-compiler/wg-llvm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Stack.20alignment.20in.20leaf.20function.html">Stack alignment in leaf function</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178882742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Stack%20alignment%20in%20leaf%20function/near/178882742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dylan MacKenzie (ecstatic-morse) <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Stack.20alignment.20in.20leaf.20function.html#178882742">(Oct 23 2019 at 18:34)</a>:</h4>
<p>Why does LLVM emit a <code>push</code>/<code>pop</code> for <a href="https://godbolt.org/z/qM23or" target="_blank" title="https://godbolt.org/z/qM23or">this example</a>? I posted a <a href="https://github.com/rust-lang/rust/issues/62531#issuecomment-545568996" target="_blank" title="https://github.com/rust-lang/rust/issues/62531#issuecomment-545568996">half-baked theory</a>, but I don't have very much experience with LLVM IR. Obviously this isn't a huge deal, just curious.</p>



<a name="178883669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Stack%20alignment%20in%20leaf%20function/near/178883669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Stack.20alignment.20in.20leaf.20function.html#178883669">(Oct 23 2019 at 18:46)</a>:</h4>
<p>I am pretty sure your theory is false. <code>-Cllvm-args=-print-after-all</code> shows that the final IR before instruction selection has no calls (though it has a bunch of loads, stores, and compares that should have been constant folded) and the MachineIR is just "ret 1" aside from debuginfo</p>



<a name="178883997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Stack%20alignment%20in%20leaf%20function/near/178883997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Stack.20alignment.20in.20leaf.20function.html#178883997">(Oct 23 2019 at 18:51)</a>:</h4>
<p>Oh no, the MIR also has stack slots allocated, even though they are dead. That might have something to do with it?</p>



<a name="178884029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Stack%20alignment%20in%20leaf%20function/near/178884029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Stack.20alignment.20in.20leaf.20function.html#178884029">(Oct 23 2019 at 18:51)</a>:</h4>
<div class="codehilite"><pre><span></span># *** IR Dump After Finalize ISel and expand pseudo-instructions ***:
# Machine code for function _RNvCsbDqzXfLQacH_7example7compare: IsSSA, TracksLiveness
Frame Objects:
  fi#0: size=4, align=1, at location [SP+8]
  fi#1: size=4, align=4, at location [SP+8]

bb.0 (%ir-block.0):
  LIFETIME_START %stack.1
  LIFETIME_START %stack.0
  LIFETIME_END %stack.1
  LIFETIME_END %stack.0
  %0:gr8 = MOV8ri 1
  $al = COPY %0:gr8
  RET 0, $al
</pre></div>



<a name="178884088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Stack%20alignment%20in%20leaf%20function/near/178884088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Stack.20alignment.20in.20leaf.20function.html#178884088">(Oct 23 2019 at 18:52)</a>:</h4>
<p>(this is with <code>-Cdebuginfo=0</code>)</p>



<a name="178884848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Stack%20alignment%20in%20leaf%20function/near/178884848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Stack.20alignment.20in.20leaf.20function.html#178884848">(Oct 23 2019 at 19:00)</a>:</h4>
<p>LLVM expands memcmp/bcmp in the ExpandMemcmp pass prior to SDAG lowering. As this happens very late, there's no opportunity for general combining passes (like InstCombine) to run anymore. The simplification happens in DAGCombine, which is not able to eliminate those ligetime.start/end pairs.</p>



<a name="178885022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Stack%20alignment%20in%20leaf%20function/near/178885022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Stack.20alignment.20in.20leaf.20function.html#178885022">(Oct 23 2019 at 19:02)</a>:</h4>
<p>I think there were some plans to move this expansion into the opt pipeline...</p>



<a name="178885233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Stack%20alignment%20in%20leaf%20function/near/178885233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Stack.20alignment.20in.20leaf.20function.html#178885233">(Oct 23 2019 at 19:04)</a>:</h4>
<p>Indeed: <a href="https://reviews.llvm.org/D60318" target="_blank" title="https://reviews.llvm.org/D60318">https://reviews.llvm.org/D60318</a> Looks like it got applied + reverted two times.</p>



<a name="178885296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Stack%20alignment%20in%20leaf%20function/near/178885296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Stack.20alignment.20in.20leaf.20function.html#178885296">(Oct 23 2019 at 19:05)</a>:</h4>
<p>Cursed</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>